#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

void swap(int &a,int &b)
{
	int t = a;
	a = b;
	b = t;
} 

void randomArr(int *arrP,int n)
{
	srand((int)time(0));
	for(int i=0;i<n;i++)
		arrP[i]=rand();
}

bool checkSort(int *arr,int n)
{
	for(int i=0;i<n-1;i++){
		if (arr[i]>arr[i+1])
			return false;
	}
	return true;
}

void printArr(int *arrP,int n)
{
    for (int i = 0; i < n; ++i)
    {
        printf("%d ",*arrP++);
//        arrP++;
    }
    printf("\n");
}

int main()
{
    int a[] = {8,7,6,5,9,1};
    int length = 6;
    printArr(a,length);
    int step = 1;
    for (int i = 0; i < length; ++i)
    {
        int j = i;
        int cur = a[j + 1];
        while (j >= 0 && cur < a[j])
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1]=cur;
    }
    printArr(a,length);
}
